package com.hfdg.coordination.ctrl;

import com.hfdg.prototype.base.model.AjaxResult;
import com.hfdg.coordination.entity.CoordAttachment;
import com.hfdg.coordination.service.CoordAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.Model;

/**
 * @ClassName CoordAttachmentCtrl
 * @Description TODO
 * @Company 会飞的锅工作室
 * @Author yuelh
 * @Email 18695867679@163.com
 * @Date 2020/05/18 07:02:29
 * @Version 1.0
 **/
@Controller
@RequestMapping("/coordAttachment")
public class CoordAttachmentCtrl {
    @Autowired
    CoordAttachmentService coordAttachmentService;
     /**
     * @Author: yuelh
     * @Description:  TODO 保存数据
     * @Date:  2020/05/18 19:02:29
     * @Param: coordAttachment
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save (CoordAttachment coordAttachment){
        if(null!=coordAttachment.getUid()&&!"".equals(coordAttachment.getUid().trim())){
            coordAttachmentService.update(coordAttachment);
        }else{
           coordAttachmentService.insert(coordAttachment);
        }
        return AjaxResult.success();
    }
     /**
     * @Author: yuelh
     * @Description:  TODO 根据UID删除数据
     * @Date:  2020/05/18 19:02:29
     * @Param: uid 要删除的数据条目的uid
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String uid){
            coordAttachmentService.delete(uid);
            return AjaxResult.success();
    }
    /**
         * @Author: yuelh
         * @Description:  TODO 根据UID删除数据
         * @Date:  2020/05/18 19:02:29
         * @Param: uid 要删除的数据条目的uid
         * @return: com.hfdg.base.domains.AjaxResult
         **/
        @RequestMapping("/batchRemove")
        @ResponseBody
        public AjaxResult batchRemove(@RequestParam("uids[]") String[] uids){
                 coordAttachmentService.batchDelete(uids);
                return AjaxResult.success();
        }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表
     * @Date:  2020/05/18 19:02:29
     * @Param: coordAttachment 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/list")
    @ResponseBody
    public  AjaxResult list(CoordAttachment coordAttachment){
        return AjaxResult.success(coordAttachmentService.list(coordAttachment));
    }
    /**
     * @Author: yuelh
     * @Description:  TODO 数据列表,分页
     * @Date:  2020/05/18 19:02:29
     * @Param: offset 数据偏移值，limit 单页最大记录数，orderBy 排序字段 ，coordAttachment 查询条件
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/getPagingData")
    @ResponseBody
    public AjaxResult getPagingData(Integer offset,Integer limit,String orderBy,CoordAttachment coordAttachment){
        return  AjaxResult.success(coordAttachmentService.getPagingData(offset,limit,orderBy,coordAttachment));
    }

     /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至表单页面
     * @Date:  2020/05/18 19:02:29
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toCreateView")
    public String toForm(HttpServletRequest request, HttpServletResponse response,Model model){
        return "commons/"+"coordination"+"/"+"coordAttachmentCreateView";
    }

/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至编辑页面
     * @Date:  2020/05/18 19:02:29
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toEditView")
    public String toEditView(HttpServletRequest request, HttpServletResponse response,String uid,Model model){
            CoordAttachment coordAttachment= coordAttachmentService.get(uid);
            model.addAttribute("formData",coordAttachment);
            return "commons/"+"coordination"+"/"+"coordAttachmentEditView";
        }


/**
     * @Author: yuelh
     * @Description:  TODO 页面跳转,跳转至对应列表页面
     * @Date:  2020/05/18 19:02:29
     * @Param: 如果有UID,则查询出页面数据并返回前台
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/toListView")
    public String toListView(HttpServletRequest request, HttpServletResponse response){
        return "commons/"+"coordination"+"/"+"coordAttachmentListView";
    }

    /**
     * @Author: yuelh
     * @Description:  TODO 页面跳转
     * @Date:  2020/05/18 19:02:29
     * @Param: page  要跳转的页面
     * @return: com.hfdg.base.domains.AjaxResult
     **/
    @RequestMapping("/view/{page}")
    public String view(HttpServletRequest request, HttpServletResponse response, @PathVariable("page") String page){
        return "commons/"+"coordination"+"/"+page;
    }


}
